package patch;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EAnnotation;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.uml2.uml.NamedElement;
import org.eclipse.uml2.uml.ProfileApplication;
import org.eclipse.uml2.uml.internal.operations.ProfileApplicationOperations;

@SuppressWarnings("restriction")
public class ProfileApplicationOperations2 extends ProfileApplicationOperations {

	/**
	 * <!-- begin-user-doc --> <!-- end-user-doc --> <!-- begin-model-doc -->
	 * Retrieves the definition (Ecore representation) of the specified named
	 * element in the profile associated with this profile application.
	 * 
	 * @param profileApplication
	 *            The receiving '<em><b>Profile Application</b></em>' model
	 *            object.
	 * @param namedElement
	 *            The named element for which to retrieve the applied
	 *            definition. <!-- end-model-doc -->
	 * @generated NOT
	 */
	public static ENamedElement getAppliedDefinition(
			ProfileApplication profileApplication, NamedElement namedElement) {
		EPackage pack = ProfileApplicationOperations2.getAppliedDefinition(profileApplication);
		return ProfileOperations2.getDefinition2(
				profileApplication.getAppliedProfile(), namedElement, pack);
	}
	
	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * <!-- begin-model-doc -->
	 * Retrieves the definition (Ecore representation) of the profile associated with this profile application.
	 * @param profileApplication The receiving '<em><b>Profile Application</b></em>' model object.
	 * <!-- end-model-doc -->
	 * @generated NOT
	 */
	public static EPackage getAppliedDefinition(ProfileApplication profileApplication) {
		EAnnotation eAnnotation = profileApplication
			.getEAnnotation(UML2_UML_PACKAGE_2_0_NS_URI);

		if (eAnnotation != null) {
			EList<EObject> references = eAnnotation.getReferences();

			if (references.size() > 0) {
				EObject obj = references.get(0);
				if (!(obj instanceof EPackage)) {
					System.out.println(obj);					
				}
				return (EPackage) obj;
			}
		}

		return null;
	}


}
